package com.hns.can.base.service;

import com.hns.can.base.entity.*;
import com.hns.can.base.vo.AuthorityFuncParamVo;
import com.hns.can.base.vo.SysAuthorityFuncVo;
import com.hns.can.common.entity.BaseEntity;
import com.hns.can.common.vo.CommonParamsVo;
import com.hns.frame.service.CommonService;
import com.hns.tool.pub.DataConvertUtil;
import com.hns.tool.pub.PubUtil;
import com.hns.tool.pub.SearchConditionVo;
import com.hns.tool.pub.UtilString;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

/**
 * 功能权限设置service
 * @author:Fisher
 * @email:zhuangcaijin@126.com
 * @version Revision 2.0.0
 */
@Service
public class SysAuthorityFuncService extends CommonService {
    
    /**
     * @author:zy
     * @email:zhangyu2222z@sina.cn
     * @创建日期:2014-6-9
     * @功能说明：获取权限树信息
     */
    @SuppressWarnings("unchecked")
    public List<SysAuthorityFuncVo> getFuncTreeData(String roleId, String level) {
        String sql = "sysAuthorityFunc.getFuncData";
        HashMap<String, String> paramMap=new HashMap<String, String>();
        
        if("99999999999999999999999999999999".equals(roleId)){
            sql = "sysAuthorityFunc.getFuncDataAll";
        }else if("0".equals(level)){
            paramMap.put("roleId", roleId);
        }else{
            //取得上级角色拥有的功能权限，避免下级角色分配时大于上级角色
            String parentRoleId = (String) sqlMapDao.selectOne("sysAuthorityFunc.getParentRoleId", roleId);
            paramMap.put("roleId", parentRoleId);
        }
        List<SysAuthorityFuncVo> list = PubUtil.convertListMapToObject(sqlMapDao.selectList(sql, paramMap), SysAuthorityFuncVo.class);
        return list;
    }
    
    /**
     * @author:zy
     * @email:zhangyu2222z@sina.cn
     * @创建日期:2014-6-9
     * @功能说明：获取已授权的功能
     */
    @SuppressWarnings("unchecked")
    public List<SysAuthorityFuncVo> getCheckedFuncData(String roleId) {
        SysAuthorityFuncEntity entity = new SysAuthorityFuncEntity();
        entity.setRoleId(roleId);
        List<SysAuthorityFuncVo> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("sysAuthorityFunc.getCheckedFuncData", entity), SysAuthorityFuncVo.class);
        return list;
    }
    
    /**
     * @author:zy
     * @email:zhangyu2222z@sina.cn
     * @创建日期:2014-6-10
     * @功能说明：编辑指定角色对应功能和按钮权限
     */
    @SuppressWarnings({"unchecked", "rawtypes" })
    @Transactional
    public void saveAuthority(String[] funcIds, String[] buttonIds, String[] fieldIds, String[] fieldAliases, String roleId, String ufuncId) {
        // 删除角色功能关系
        SysAuthorityFuncEntity funcEntity = new SysAuthorityFuncEntity();
        SysAuthrityButtonEntity buttonEntity = new SysAuthrityButtonEntity();
        funcEntity.setRoleId(PubUtil.filterNULL(roleId));
        
        Map map = new HashMap();
        map.put("roleId", roleId);
        
        // 删除角色功能关系
//        commonEntityDao.deleteByParamsIgnoreNullValue(SysAuthorityFuncEntity.class, map);
        this.sqlMapDao.delete("sysAuthorityFunc.deleteAuthFuncForUpt", map);
        // 删除角色按钮关系
//        commonEntityDao.deleteByParamsIgnoreNullValue(SysAuthrityButtonEntity.class, map);
        this.sqlMapDao.delete("sysAuthorityFunc.deleteAuthButtonForUpt", map);
        // 删除角色字段权限数据
//        if(PubUtil.isNotEmpty(ufuncId)){
//            map.put("ufuncId", ufuncId);
//            this.sqlMapDao.delete("sysAuthorityFunc.deleteAuthFieldForUpt", map);
//        }
        
        if(PubUtil.isNotEmpty(funcIds)){
        	// 添加角色功能关系
        	for (String funcId : funcIds) {
        		funcEntity = new SysAuthorityFuncEntity();
        		funcEntity.setId(UtilString.getUUID());
        		funcEntity.setRoleId(roleId);
        		funcEntity.setFuncId(PubUtil.filterNULL(funcId));
        		funcEntity.setCreateTs(new Date());
        		commonEntityDao.save(funcEntity);
        	}
        }
        if(PubUtil.isNotEmpty(buttonIds)){
        	// 添加角色按钮关系
        	for (String buttonId : buttonIds) {
        		buttonEntity = new SysAuthrityButtonEntity();
        		buttonEntity.setId(UtilString.getUUID());
        		buttonEntity.setRoleId(roleId);
        		buttonEntity.setButtonId(PubUtil.filterNULL(buttonId));
        		buttonEntity.setCreateTs(new Date());
        		commonEntityDao.save(buttonEntity);
        	}
        }
        // 添加角色字段权限数据
//        if(PubUtil.isNotEmpty(ufuncId) && PubUtil.isNotEmpty(fieldIds)){
//            for(int i = 0; i < fieldIds.length; i++){
//                SysAuthrityFieldEntity fieldEntity = new SysAuthrityFieldEntity();
//                fieldEntity.setId(UtilString.getUUID());
//                fieldEntity.setRoleId(roleId);
//                fieldEntity.setFieldId(fieldIds[i]);
//                fieldEntity.setFieldAlias(fieldAliases[i]);
//                fieldEntity.setCreateTs(new Date());
//                commonEntityDao.save(fieldEntity);
//            }
//        }
        
    }
    
    /**
     * @author:cwm
     * @email:112362667@qq.com
     * @创建日期:2015-3-31
     * @功能说明： 取消下级角色对应的功能、按钮、字段权限
     */
    @SuppressWarnings({"unchecked", "rawtypes" })
    @Transactional
    public void cancelAuthorityFunc(String roleId, String ufuncId) {
        Map map = new HashMap();
        map.put("roleId", roleId);
        
        // 清理下级角色对应的功能、按钮、字段权限
        this.sqlMapDao.delete("sysAuthorityFunc.deleteAuthFunc", map);
        this.sqlMapDao.delete("sysAuthorityFunc.deleteAuthButton", map);
        if(PubUtil.isNotEmpty(ufuncId)){
            this.sqlMapDao.delete("sysAuthorityFunc.deleteAuthField", map);
        }
    }

    /**
     * @author:zy
     * @email:zhangyu2222z@sina.cn
     * @创建日期:2014-6-13
     * @功能说明：编辑指定角色对应数据权限
     */
    @SuppressWarnings({"rawtypes", "unchecked" })
    @Transactional
    public void saveResAuthority(String[] dataIds, String[] isFulls, String dataType, String roleId) {
        //删除角色对应数据权限
        SysAuthorityResourceEntity entity = new SysAuthorityResourceEntity();
        entity.setRoleId(roleId);
        Map map = DataConvertUtil.ConvertObjToMap(entity);
        commonEntityDao.deleteByParamsIgnoreNullValue(SysAuthorityResourceEntity.class, map);

        //如果事机构类型，保存对应线路
        if("RES00000".equals(dataType)){
            //获取对应线路信息
            //----传入机构id找线路id
            for (int i=0;i<dataIds.length;i++) {
                TmpOrganStorageEntity organStorageEntity = new TmpOrganStorageEntity();
                organStorageEntity.setId(UtilString.getUUID());
                organStorageEntity.setOrganId(dataIds[i]);
                commonEntityDao.save(organStorageEntity);
                if(i % 100 == 0){
                    commonEntityDao.flush();
                }
            }
            commonEntityDao.flush();
            //----保存线路id
            List<CommonParamsVo> list = PubUtil.convertListMapToObject(this.sqlMapDao.selectList("sysAuthorityFunc.getTmpSaveLineIds"), CommonParamsVo.class);
            for(int i=0;i<list.size();i++){
                entity = new SysAuthorityResourceEntity();
                entity.setId(UtilString.getUUID());
                entity.setRoleId(roleId);
                entity.setResDataId(list.get(i).getLineId());
                entity.setResType(dataType);
                entity.setIsFull("1");
                entity.setCreateTs(new Date());
                commonEntityDao.save(entity);
            }
        }
        //保存角色对应数据权限
        for(int i=0;i<dataIds.length;i++){
            entity = new SysAuthorityResourceEntity();
            entity.setId(UtilString.getUUID());
            entity.setRoleId(roleId);
            entity.setResDataId(dataIds[i]);
            entity.setResType(dataType);
            entity.setIsFull(isFulls[i]);
            entity.setCreateTs(new Date());
            commonEntityDao.save(entity);
        }
    }
    
    /**
     * @author:cwm
     * @email:112362667@qq.com
     * @创建日期:2015-3-31
     * @功能说明： 取消下级角色对应的数据权限
     */
    @SuppressWarnings({"unchecked", "rawtypes" })
    @Transactional
    public void cancelAuthorityRes(String roleId) {
        Map map = new HashMap();
        map.put("roleId", roleId);
        
        // 清理下级角色对应的数据权限
        this.sqlMapDao.delete("sysAuthorityFunc.deleteAuthRes", map);
    }
    
    /**
     * @author:zy
     * @email:zhangyu2222z@sina.cn
     * @创建日期:2014-6-13
     * @功能说明：获取数据权限树
     */
    @SuppressWarnings("unchecked")
    public List<BaseEntity> getResTreeData(String roleId, String corpId, String level, String roleType, String selResType) {
        String sql = "sysAuthorityFunc.getResTreeList";
        HashMap<String, String> paramMap = new HashMap<String, String>();
        paramMap.put("selResType", selResType);
        if ("ROLT0001".equals(roleType)) {
            sql = "sysAuthorityFunc.getResTreeListAll";
        } else if ("0".equals(level)) {
            paramMap.put("corpId", corpId);
            paramMap.put("roleId", roleId);
        } else {
            paramMap.put("corpId", corpId);
            // 取得上级角色拥有的功能权限，避免下级角色分配时大于上级角色
            String parentRoleId = (String) sqlMapDao.selectOne("sysAuthorityFunc.getParentRoleId", roleId);
            paramMap.put("roleId", parentRoleId);
        }
        
        List<BaseEntity> list = PubUtil.convertListMapToObject(this.sqlMapDao.selectList(sql, paramMap), BaseOrganEntity.class);
        return list;
    }
    
    /**
     * @author:zy
     * @email:zhangyu2222z@sina.cn
     * @创建日期:2014-6-13
     * @功能说明：获取角色对应的数据权限
     */
    @SuppressWarnings({"unchecked" })
    public List<SysAuthorityResourceEntity> getCheckedResData(String roleId) {
        SysAuthorityResourceEntity entity = new SysAuthorityResourceEntity();
        entity.setRoleId(roleId);
        List<SysAuthorityResourceEntity> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("sysAuthorityFunc.getCheckedResData", entity), SysAuthorityResourceEntity.class);
        return list;
    }
    
    /**
     * @author:chenwm
     * @email:112362667@qq.com
     * @创建日期:2015-01-23
     * @功能说明：获取资源字段值权限信息
     */
    @SuppressWarnings("unchecked")
    public List<SysAuthrityFieldValueEntity> getAuthFieldValue(String userId) {
    	HashMap<String, String> paramMap=new HashMap<String, String>();
	 	paramMap.put("userId", userId);
        List<SysAuthrityFieldValueEntity> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("sysAuthorityFunc.getAuthFieldValue", paramMap), SysAuthrityFieldValueEntity.class);
        return list;
    }
    
    /**
     * @author:chenwm
     * @email:112362667@qq.com
     * @创建日期:2015-03-01
     * @功能说明：获取资源字段权限信息
     */
    @SuppressWarnings("unchecked")
    public List<SysAuthrityFieldEntity> getAuthField(String userId, String tableId) {
    	HashMap<String, String> paramMap=new HashMap<String, String>();
	 	paramMap.put("userId", userId);
	 	paramMap.put("tableId", tableId);
        List<SysAuthrityFieldEntity> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("sysAuthorityFunc.getAuthField", paramMap), SysAuthrityFieldEntity.class);
        return list;
    }
    
    /**
     * @author:chenwm
     * @email:112362667@qq.com
     * @创建日期:2015-07-29
     * @功能说明：获取资源字段权限信息
     */
    @SuppressWarnings("unchecked")
    public List<SysAuthrityFieldEntity> getAuthFieldByUser(String userId) {
    	HashMap<String, String> paramMap=new HashMap<String, String>();
	 	paramMap.put("userId", userId);
        List<SysAuthrityFieldEntity> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("sysAuthorityFunc.getAuthFieldByUser", paramMap), SysAuthrityFieldEntity.class);
        return list;
    }
    
    /**
     * @author:chenwm
     * @email:112362667@qq.com
     * @创建日期:2015-07-29
     * @功能说明：获取资源字段权限信息
     */
    public String getAuthFuncId(String url) {
    	HashMap<String, String> paramMap=new HashMap<String, String>();
	 	paramMap.put("url", url);
	 	
	 	String funcId = (String) sqlMapDao.selectOne("sysAuthorityFunc.getAuthFuncId", paramMap);
        return funcId;
    }

    /**
     * @param userId
     * @param request
     * @return
     * @author:JeffXu
     * @email:835264047@qq.com
     * @创建日期:2015-3-13
     * @功能说明：获取当前用户拥有的资源权限数据
     */
    @SuppressWarnings("unchecked")
    @Transactional
    public List<SysFieldValueRegisterEntity> getCurrentAccessResData(String roleId, String level) {
        String sql = "sysAuthorityFunc.getCurrentAccessResData";
        HashMap<String, String> paramMap = new HashMap<String, String>();
        
        if ("99999999999999999999999999999999".equals(roleId)) {
            sql = "sysAuthorityFunc.getCurrentAccessResDataAll";
        } else if ("0".equals(level)) {
            paramMap.put("roleId", roleId);
        } else {
            // 取得上级角色拥有的功能权限，避免下级角色分配时大于上级角色
            String parentRoleId = (String) sqlMapDao.selectOne("sysAuthorityFunc.getParentRoleId", roleId);
            paramMap.put("roleId", parentRoleId);
        }
        
        List<SysFieldValueRegisterEntity> list = PubUtil.convertListMapToObject(sqlMapDao.selectList(sql, paramMap), SysFieldValueRegisterEntity.class);
        return list;
    }
    
    /**
     * @param roleId
     * @param request
     * @return
     * @author:JeffXu
     * @email:835264047@qq.com
     * @创建日期:2015-3-13
     * @功能说明：获取选中角色拥有的资源权限数据
     */
    @SuppressWarnings("unchecked")
    @Transactional
    public List<SysFieldValueRegisterEntity> getCheckedAccessResData(String roleId) {
        List<SysFieldValueRegisterEntity> list = PubUtil.convertListMapToObject(
            sqlMapDao.selectList("sysAuthorityFunc.getCheckedAccessResData", roleId), SysFieldValueRegisterEntity.class);
        return list;
    }
    
    /**
     * @param roleId
     * @param fieldValueIds
     * @author:JeffXu
     * @email:835264047@qq.com
     * @创建日期:2015-3-16
     * @功能说明：编辑指定角色对应资源权限
     */
    @Transactional
    public void saveAccessResAuthority(String roleId, String[] fieldValueIds) {
        // 对应角色的资源权限
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("roleId", roleId);
        commonEntityDao.deleteByParamsIgnoreNullValue(SysAuthrityFieldValueEntity.class, map);
        
        for(int i = 0; i < fieldValueIds.length; i++){
            SysAuthrityFieldValueEntity entity = new SysAuthrityFieldValueEntity();
            entity.setId(UtilString.getUUID());
            entity.setRoleId(roleId);
            entity.setFieldValueId(fieldValueIds[i]);
            entity.setCreateTs(new Date());
            commonEntityDao.save(entity);
        }
    }
    
    /**
     * @author:cwm
     * @email:112362667@qq.com
     * @创建日期:2015-3-31
     * @功能说明： 取消下级角色对应的资源权限
     */
    @SuppressWarnings({"unchecked", "rawtypes" })
    @Transactional
    public void cancelAuthorityFieldValue(String roleId) {
        Map map = new HashMap();
        map.put("roleId", roleId);
        
        // 清理下级角色对应的资源权限
        this.sqlMapDao.delete("sysAuthorityFunc.deleteAuthFieldValue", map);
    }

    /**
     * @param paramMap
     * @return
     * @author:JeffXu
     * @email:835264047@qq.com
     * @创建日期:2015-3-16
     * @功能说明：获取当前用户所拥有的字段权限数据
     * @    upt by jeffxu 150410
     */
    @SuppressWarnings("unchecked")
    @Transactional
    public List<SysFieldRegisterEntity> getCurrentFieldData(String funcId, String roleId, String level) {
        String sql = "sysAuthorityFunc.getCurrentFieldData";
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("funcId", funcId);
        
        if("99999999999999999999999999999999".equals(roleId)){
            paramMap.put("roleId", roleId);
            sql = "sysAuthorityFunc.getCurrentFieldDataAll";
        }else if("0".equals(level)){
            paramMap.put("roleId", roleId);
        }else{
            //取得上级角色拥有的功能权限，避免下级角色分配时大于上级角色
            String parentRoleId = (String) sqlMapDao.selectOne("sysAuthorityFunc.getParentRoleId", roleId);
            paramMap.put("roleId", parentRoleId);
        }
        List<SysFieldRegisterEntity> list = PubUtil.convertListMapToObject(sqlMapDao.selectList(sql, paramMap), SysFieldRegisterEntity.class);
        return list;
    }

    /**
     * @param paramMap
     * @return
     * @author:JeffXu
     * @email:835264047@qq.com
     * @创建日期:2015-3-16
     * @功能说明：获取选中角色所拥有的字段权限数据
     */
    @SuppressWarnings("unchecked")
    @Transactional
    public List<SysFieldRegisterEntity> getCheckedFieldData(Map<String, Object> paramMap) {
        List<SysFieldRegisterEntity> list = PubUtil.convertListMapToObject(
            sqlMapDao.selectList("sysAuthorityFunc.getCheckedFieldData", paramMap), SysFieldRegisterEntity.class);
        return list;
    }
    
    /**
     * @param roleId
     * @param parentRoleId
     * @author:JeffXu
     * @email:835264047@qq.com
     * @创建日期:2015-7-29
     * @功能说明：#upt by jeffxu(字段权限) 取父级角色拥有的字段权限分配给角色
     */
    @SuppressWarnings("unchecked")
    @Transactional
    public void addParentFieldDataToRole(String roleId, String parentRoleId) {
        if (PubUtil.isNotEmpty(parentRoleId)) {
            List<SysAuthrityFieldEntity> list = PubUtil.convertListMapToObject(
                sqlMapDao.selectList("sysAuthorityFunc.getParentFieldData", parentRoleId), SysAuthrityFieldEntity.class);
            if(PubUtil.isNotEmpty(list)){
                for (int i = 0; i < list.size(); i++) {
                    SysAuthrityFieldEntity entity = new SysAuthrityFieldEntity();
                    SysAuthrityFieldEntity tmpEntity = list.get(i);
                    entity.setId(UtilString.getUUID());
                    entity.setRoleId(roleId);
                    entity.setCreateTs(new Date());
                    entity.setFieldId(tmpEntity.getFieldId());
                    entity.setFieldAlias(tmpEntity.getFieldAlias());
                    entity.setFieldSn(tmpEntity.getFieldSn());
                    commonEntityDao.save(entity);
                }
            }
        }
    }

    /**
     * @author:zy
     * @email:zhangyu2222z@sina.cn
     * @创建日期:2017-3-17
     * @功能说明：获取已授权的功能id
     */
    public List<SysAuthorityFuncVo> getCheckedFuncCache(Set<SysRoleEntity> setRole) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("setRole", setRole);
        List<SysAuthorityFuncVo> list = PubUtil.convertListMapToObject(
                this.sqlMapDao.selectList("sysAuthorityFunc.getCheckedFuncCache", paramMap), SysAuthorityFuncVo.class);
        return list;
    }

    /**
     * @author:zy
     * @email:zhangyu2222z@sina.cn
     * @创建日期:2017-3-24
     * @功能说明：获取拥有字段权限设置的功能表
     */
    public List<SysFuncRegisterEntity> getAuthFuncList(AuthorityFuncParamVo params) {
        String sql = "sysAuthorityFunc.getAuthFuncList";
        if("ROLT0001".equals(params.getRoleType())){
            sql = "sysAuthorityFunc.getAuthFuncListAll";
        }
        List<SysFuncRegisterEntity> list = PubUtil.convertListMapToObject(this.sqlMapDao.selectList(sql, params), SysFuncRegisterEntity.class);
        return list;
    }

    /**
     * @author:zy
     * @email:zhangyu2222z@sina.cn
     * @创建日期:2017-3-24
     * @功能说明：保存功能字段权限
     */
    @Transactional
    public void saveFieldAuthority(AuthorityFuncParamVo params) {
        Map map = new HashMap();
        map.put("roleId", params.getRoleId());
        if(PubUtil.isNotEmpty(params.getFuncId())){
            map.put("ufuncId", params.getFuncId());
            this.sqlMapDao.delete("sysAuthorityFunc.deleteAuthFieldForUpt", map);
        }
        if(PubUtil.isNotEmpty(params.getFuncId()) && PubUtil.isNotEmpty(params.getFieldIds())){
            String[] fieldAliases = params.getFieldAliases();
            String[] fieldIds = params.getFieldIds();
            for(int i = 0; i < fieldIds.length; i++){
                SysAuthrityFieldEntity fieldEntity = new SysAuthrityFieldEntity();
                fieldEntity.setId(UtilString.getUUID());
                fieldEntity.setRoleId(params.getRoleId());
                fieldEntity.setFieldId(fieldIds[i]);
                if(i < fieldAliases.length){
                    fieldEntity.setFieldAlias(fieldAliases[i]);
                }
                fieldEntity.setCreateTs(new Date());
                commonEntityDao.save(fieldEntity);
            }
        }

    }

    /**
     * @author:zy
     * @email:zhangyu2222z@sina.cn
     * @创建日期:2017-3-17
     * @功能说明：获取功能权限用于生成表
     */
    public List<SysAuthorityFuncVo> getFuncDataResList(AuthorityFuncParamVo params) {
        String sqlStr = "sysAuthorityFunc.getFuncDataResList";
        if("ROLT0001".equals(params.getRoleType())){
            sqlStr = "sysAuthorityFunc.getFuncDataResListAll";
        }

        List<SysAuthorityFuncVo> resultlist = PubUtil.convertListMapToObject(
                this.sqlMapDao.selectList(sqlStr, params), SysAuthorityFuncVo.class);
        //二级菜单
        HashMap<String, List<SysAuthorityFuncVo>> secondLv = new HashMap<String, List<SysAuthorityFuncVo>>();
        //三级菜单
        HashMap<String, List<SysAuthorityFuncVo>> thirdLv = new HashMap<String, List<SysAuthorityFuncVo>>();
        //四级菜单
        HashMap<String, List<SysAuthorityFuncVo>> forthLv = new HashMap<String, List<SysAuthorityFuncVo>>();
        //五级菜单
        HashMap<String, List<SysAuthorityFuncVo>> fifthLv = new HashMap<String, List<SysAuthorityFuncVo>>();
        //按钮
        HashMap<String, List<SysAuthorityFuncVo>> buttons = new HashMap<String, List<SysAuthorityFuncVo>>();

        List<SysAuthorityFuncVo> volist = new ArrayList<SysAuthorityFuncVo>();

        for(SysAuthorityFuncVo vo : resultlist){
            if(1 == vo.getScale().intValue()){
                volist.add(vo);
            }else if(2 == vo.getScale().intValue()){
                if(null == secondLv.get(vo.getFuncId())){
                    secondLv.put(vo.getFuncId(),new ArrayList<SysAuthorityFuncVo>());
                }
                secondLv.get(vo.getFuncId()).add(vo);
            }else if(3 == vo.getScale().intValue()){
                if(null == thirdLv.get(vo.getFuncId())){
                    thirdLv.put(vo.getFuncId(),new ArrayList<SysAuthorityFuncVo>());
                }
                thirdLv.get(vo.getFuncId()).add(vo);
            }else if(4 == vo.getScale().intValue()){
                if(null == forthLv.get(vo.getFuncId())){
                    forthLv.put(vo.getFuncId(),new ArrayList<SysAuthorityFuncVo>());
                }
                forthLv.get(vo.getFuncId()).add(vo);
            }else if(5 == vo.getScale().intValue()){
                if(null == fifthLv.get(vo.getFuncId())){
                    fifthLv.put(vo.getFuncId(),new ArrayList<SysAuthorityFuncVo>());
                }
                fifthLv.get(vo.getFuncId()).add(vo);
            }else if(6 == vo.getScale().intValue()){
                if(null == buttons.get(vo.getFuncId())){
                    buttons.put(vo.getFuncId(),new ArrayList<SysAuthorityFuncVo>());
                }
                buttons.get(vo.getFuncId()).add(vo);
            }
        }
        for(SysAuthorityFuncVo vo1 : volist){
            if(PubUtil.isNotEmpty(secondLv.get(vo1.getId()))){
                List<SysAuthorityFuncVo> secondList = secondLv.get(vo1.getId());
                for(SysAuthorityFuncVo vo2 : secondList){
                    if(PubUtil.isNotEmpty(thirdLv.get(vo2.getId()))){
                        List<SysAuthorityFuncVo> thirdList = thirdLv.get(vo2.getId());
                        //直接加四级菜单
                        List<SysAuthorityFuncVo> combinList = new ArrayList<SysAuthorityFuncVo>();
                        for(SysAuthorityFuncVo vo3 : thirdList){
                            if(PubUtil.isNotEmpty(forthLv.get(vo3.getId()))){
                                List<SysAuthorityFuncVo> fouthList = forthLv.get(vo3.getId());
                                for(SysAuthorityFuncVo vo4 : fouthList){
                                    if(PubUtil.isNotEmpty(fifthLv.get(vo4.getId()))){
                                        List<SysAuthorityFuncVo> fifthList = fifthLv.get(vo4.getId());
                                        for(SysAuthorityFuncVo vo5 : fifthList){
                                            if(PubUtil.isNotEmpty(buttons.get(vo5.getId()))){
                                                List<SysAuthorityFuncVo> btnList = buttons.get(vo5.getId());
                                                vo5.setChild(btnList);
                                            }
                                        }
                                        vo4.setChild(fifthList);
                                    }
                                }
                                combinList.addAll(fouthList);

                            }
                        }
                        vo2.setChild(combinList);
                    }
                }
                vo1.setChild(secondList);
            }
        }
        return volist;
    }

}
